<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script type="text/javascript">
        class Father{
            constructor(){
                this.eat = this.eat.bind(this); // 始终固定this指向 Father
            }
            get fruit(){
                return 'apple';
            }
            eat(){
                console.log('eat a '+ this.fruit);
            }
        }
        class Son{
            get fruit(){
                return 'pear';
            }
        }
        const father = new Father();
        const son = new Son();
        son.eat = father.eat; // 使用father的eat方法
        father.eat()
        // son.eat() // 如果不固定this指向 eat a pear
        son.eat() // 如果固定this指向 eat a apple

        console.log(father,son);
    </script>
</body>
</html>